package com.biyu.monitormanage.common.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 *
 * @author biyubing
 * @email byb15491665510220@163.com
 * @date 2022-03-12 11:39:22
 */
public class BaseResponse extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public BaseResponse() {
        put("code", 0);
        put("msg", "success");
    }

    public static BaseResponse error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
    }

    public static BaseResponse error(String msg) {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }

    public static BaseResponse error(int code, String msg) {
        BaseResponse r = new BaseResponse();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static BaseResponse ok(String msg) {
        BaseResponse r = new BaseResponse();
        r.put("msg", msg);
        return r;
    }

    public static BaseResponse ok(Map<String, Object> map) {
        BaseResponse r = new BaseResponse();
        r.putAll(map);
        return r;
    }

    public static BaseResponse ok() {
        return new BaseResponse();
    }

    @Override
    public BaseResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
